//
//  YTMyPersoninfoVC.m
//  CllForIOS
//
//  Created by qiyun on 2018/3/19.
//  Copyright © 2018年 aRui. All rights reserved.
//

#import "YTMyPersoninfoVC.h"
#import "YTMineInfoCell.h"
#import "YTMyPersonEdit.h"
@interface YTMyPersoninfoVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView * tableView;
@property (nonatomic, strong) NSArray * titleArray;
@property (nonatomic, strong) NSArray * desArray;
@end

@implementation YTMyPersoninfoVC
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //判断登录状态
    NSMutableDictionary *data = [Tookit getUserCasheInfo];
    NSString*token= [data objectForKey:@"token"];
    if (token.length>10) {
       self.desArray=@[data[@"account"],data[@"mobile"],data[@"name"],data[@"certNo"]];
    }
    [self.tableView reloadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=RGBA(236, 236, 236);
    [self setNav];
    self.titleArray=@[@"设置账号:",@"手机号码:",@"真实姓名:",@"身份证号:"];
    self.tableView.backgroundColor=[UIColor whiteColor];
}
-(void)setNav{
    self.titleLabel.text=@"个人资料";
    self.lineView.hidden=YES;
    [self.leftimaBtn setImage:IMAGE(@"Mine_back") forState:UIControlStateNormal];
    
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, k_statusbarHeight+49, SCREEN_W, AfW(66)*4+20) style:UITableViewStylePlain];
        _tableView.separatorColor = RGBA(223, 223, 223);
        _tableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 12);
        _tableView.scrollEnabled=NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        _tableView.tableFooterView = [UIView new];
        [_tableView registerClass:[YTMineInfoCell class] forCellReuseIdentifier:@"YTMineInfoCell"];
        
        if ([_tableView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
    }
    return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  self.titleArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0001f;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView*scetionheadview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 20)];
    scetionheadview.backgroundColor=RGBA(236, 236, 236);
    return scetionheadview;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return AfW(66);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellId = @"YTMineInfoCell";
    YTMineInfoCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.title.text=self.titleArray[indexPath.row];
    cell.destitle.text=self.desArray[indexPath.row];
   
    if (indexPath.row==2||indexPath.row==3) {
        if ([cell.destitle.text isEqualToString:@"(未实名)"]) {
             cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
        if ([cell.destitle.text isEqualToString:@"(未认证)"]) {
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
  
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   if (indexPath.row==2||indexPath.row==3) {
         if ([ self.desArray[2] isEqualToString:@"(未实名)"]||[ self.desArray[3] isEqualToString:@"(未认证)"]) {
           [self.navigationController pushViewController:[YTMyPersonEdit new] animated:1];
         }
      
    }
}
@end
